<?php
// 引入另一个php文件   
@include_once('conn.php');

$user = $_GET['user'];

// 显示购物车   商品和数量不在同一张表中


// 这里的几个id
//   goods_list 商品列表  id 
//   cart_info  uid / goods_id    uid是唯一字段   
$sql = "select * from cart_info,goods_list where userid = '$user' and cart_info.goodsid = goods_list.id";

// 执行sql语句会得到一个结果集
$result = mysqli_query($conn, $sql);

$obj = [];

$list = [];

while ($arr = mysqli_fetch_array($result)) {
    $temp = [];
    $temp['userid'] = $arr['userid'];
    $temp['goodsid'] = $arr['goodsid'];
    $temp['goodsname'] = $arr['goodsname'];
    $temp['goodsprice'] = $arr['goodsprice'];
    $temp['buynum'] = $arr['buynum'];
    $temp['goodsimg'] = $arr['goodsimg'];
    array_push($list, $temp);
}
// var_dump(json_encode($list));

if ($list) {
    $obj['status'] = true;
    // 数据需要发给前端
    $obj['list'] = $list;
    $obj['msg'] = '数据库请求成功';
} else {
    $obj['status'] = false;
    $obj['msg'] = '数据库请求失败';
}

echo json_encode($obj);
